var mongoose = require('mongoose');

var dbhost = 'localhost';
//var dbhost = '64.23.72.68';
//var dbhost = '172.28.60.160';
var dbname = 'test';

var gridCollectionName = 'OpenGrid';
var timeCollectionName = 'TimePoint';

var db = mongoose.createConnection(dbhost, dbname);

//handle db connection event
db.on('error', console.error.bind(console, 'connection error.'));
db.on('open', function() {
	console.log('connected to ' + dbname + ' database on ' + dbhost);
});

var GridSchema = new mongoose.Schema({
	_id : String,
	gridx : Number,		// x axis value
	gridy : Number,		// y axis value
	writime : Number,	// created/updated time
	color : String,		// color of cell
	class : String,		// style class of cell
	//subject : String,
	keyword : String,	// search keyword
	key_id: String,		// unique identifier
	content : String,
	//good : Number,
	//bad : Number,
	opacity : Number,
	nearby : [Boolean],
	relative : [Boolean]
});

var GridModel = db.model(gridCollectionName, GridSchema);
var GridData = db.model(gridCollectionName);

var TpSchema = new mongoose.Schema({
	grid_id : String,
	timepoint : Number,
	level : Number
});

var TpModel = db.model(timeCollectionName, TpSchema);
var TpData = db.model(timeCollectionName);

exports.GridModel = GridModel;
exports.GridData = GridData;

exports.TpModel = TpModel;
exports.TpData = TpData;

